package com.api.shihua.sche;

import com.api.shihua.util.LogTool;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import weaver.general.Util;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SynUserPassword extends BaseCronJob {
    private final static LogTool log = new LogTool("/log/syn/",false);
    @Override
    public void execute() {
        SimpleDateFormat sim=new  SimpleDateFormat("yyyy-MM-dd");
        String currentDate=sim.format(new Date());
        RecordSet re=new RecordSet();
        String sql="select  id,workcode,loginid,password,textfield1 from  hrmresource where status in (0,1,2,3) ";//and lastmoddate>='"+currentDate+"'";
        re.execute(sql);
        while(re.next()){
            String id=Util.null2String(re.getString("id") ).trim();
            String workcode=Util.null2String(re.getString("workcode") ).trim();
            String loginid=Util.null2String(re.getString("loginid")).trim();
            String oldpassword=Util.null2String(re.getString("password")).trim();
            String textfield1=Util.null2String(re.getString("textfield1")).trim();//新密码

            if("".equals(loginid)){
                continue;
            }
            if(!"".equals(textfield1)){
                continue;
            }
            String password=Util.getEncrypt(loginid);
            log.writeLog(loginid+"--->"+password);
            //if(oldpassword.equals(password)){
                //continue;
            //}
            updPass(id,password);
        }
    }

/*
更新密码
 */
    public void updPass(String id,String password){
        RecordSet re=new RecordSet();
        re.execute("update hrmresource set textfield1='"+password+"' where id='"+id+"'");
    }

}
